package bat.ke.qq.com.common;

import bat.ke.qq.com.bean.Fox;
import bat.ke.qq.com.service.UserService;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
   @Override
   public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
      //创建BeanDefinition
      RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Fox.class);

      rootBeanDefinition.getPropertyValues().add("name","fox");
      // 注册到容器  beanDefinitonMap
      registry.registerBeanDefinition("fox",rootBeanDefinition);


      AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) registry.getBeanDefinition("userService");
      // constructor 注入
      beanDefinition.setAutowireMode(3);

   }
}